/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package vn.edu.vttu.readxml;

/**
 *
 * @author nhphuoc
 */
import java.io.File;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class ReadXML {
private String fileAddress="config.xml";    
    public String getInfo(String info){
        String reinfo=null;
        try {
            File file = new File(fileAddress);
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder db = dbf.newDocumentBuilder();
        Document doc = db.parse(file);
        doc.getDocumentElement().normalize();
        NodeList nodeLst = doc.getElementsByTagName("info");
        Node fstNode = nodeLst.item(0);

        if (fstNode.getNodeType() == Node.ELEMENT_NODE) {

            Element fstElmnt = (Element) fstNode;            
            NodeList lstNmElmntLst = fstElmnt.getElementsByTagName(info);
            Element lstNmElmnt = (Element) lstNmElmntLst.item(0);
            NodeList lstNm = lstNmElmnt.getChildNodes();
            reinfo = ((Node) lstNm.item(0)).getNodeValue();                   
        }
        } catch (Exception e) {
        }
        return reinfo;
    }
}
